package com.koomii.redis.demo.conf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;

import com.koomii.redis.demo.message.listener.DemoMessageListener;

@Configuration
public class RedisMessageConfig {
	@Bean
	public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
		RedisMessageListenerContainer container = new RedisMessageListenerContainer();
		container.setConnectionFactory(connectionFactory);
		return container;
	}
	@Bean
	public MessageListenerAdapter listenerAdapter(RedisMessageListenerContainer container, DemoMessageListener handler) {
		System.out.println("---------启动订阅-------");
		MessageListenerAdapter listenerAdapter = new MessageListenerAdapter(handler);
		container.addMessageListener(listenerAdapter, new PatternTopic("TEST"));
		container.addMessageListener(listenerAdapter, new PatternTopic("DEMO"));
		return listenerAdapter;
	}
}
